import { GaRegExp, ruleInject, ruleInjectable } from "../InjectionRule";
import { blankRemove } from "../methods/blank-remove";

@ruleInjectable()
export default class tryCatchRule extends GaRegExp {

	@ruleInject() private variableNameRule!: GaRegExp;

	@ruleInject() private executeRule!: GaRegExp;

	public RuleInit() {
		this.ParseRule([
			"(-", "try", this.Supply("TRY"), blankRemove, "\\{", "(", this.executeRule, ")", "\\}", blankRemove, ")",
			"(", "catch", this.Supply("TRY_CATCH"), blankRemove, "\\(", blankRemove, "(", this.variableNameRule, ")", "\\)", blankRemove, "\\{", "(", this.executeRule, ")", "\\}", blankRemove, ")+",
			"(&", "finally", this.Supply("TRY_FINALLY"), blankRemove, "\\{", "(", this.executeRule, ")", "\\}", ")?",
		]);
	}

}
